<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>qLibc: extensions/qlog.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">qLibc
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('qlog_8c.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">qlog.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Rotating file logger object.  
<a href="#details">More...</a></p>

<p><a href="qlog_8c_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:acfc1a51cddb0a4e8555ea66f42276874"><td class="memItemLeft" align="right" valign="top">qlog_t *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qlog_8c.html#acfc1a51cddb0a4e8555ea66f42276874">qlog</a> (const char *filepathfmt, mode_t mode, int rotateinterval, int options)</td></tr>
<tr class="memdesc:acfc1a51cddb0a4e8555ea66f42276874"><td class="mdescLeft">&#160;</td><td class="mdescRight">Open ratating-log file.  <a href="#acfc1a51cddb0a4e8555ea66f42276874">More...</a><br/></td></tr>
<tr class="separator:acfc1a51cddb0a4e8555ea66f42276874"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1d9678a766dbbe0cf4863296588a70ce"><td class="memItemLeft" align="right" valign="top">static bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qlog_8c.html#a1d9678a766dbbe0cf4863296588a70ce">write_</a> (qlog_t *log, const char *str)</td></tr>
<tr class="memdesc:a1d9678a766dbbe0cf4863296588a70ce"><td class="mdescLeft">&#160;</td><td class="mdescRight">qlog-&gt;write(): Log messages  <a href="#a1d9678a766dbbe0cf4863296588a70ce">More...</a><br/></td></tr>
<tr class="separator:a1d9678a766dbbe0cf4863296588a70ce"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0f1c08e4e0616731b8c5be87a8752f72"><td class="memItemLeft" align="right" valign="top">static bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qlog_8c.html#a0f1c08e4e0616731b8c5be87a8752f72">writef</a> (qlog_t *log, const char *format,...)</td></tr>
<tr class="memdesc:a0f1c08e4e0616731b8c5be87a8752f72"><td class="mdescLeft">&#160;</td><td class="mdescRight">qlog-&gt;<a class="el" href="qlog_8c.html#a0f1c08e4e0616731b8c5be87a8752f72" title="qlog-&gt;writef(): Log messages ">writef()</a>: Log messages  <a href="#a0f1c08e4e0616731b8c5be87a8752f72">More...</a><br/></td></tr>
<tr class="separator:a0f1c08e4e0616731b8c5be87a8752f72"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3c66d4096cbaac34db4659e04a0d6335"><td class="memItemLeft" align="right" valign="top">static bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qlog_8c.html#a3c66d4096cbaac34db4659e04a0d6335">duplicate</a> (qlog_t *log, FILE *outfp, bool flush)</td></tr>
<tr class="memdesc:a3c66d4096cbaac34db4659e04a0d6335"><td class="mdescLeft">&#160;</td><td class="mdescRight">qlog-&gt;<a class="el" href="qlog_8c.html#a3c66d4096cbaac34db4659e04a0d6335" title="qlog-&gt;duplicate(): Duplicate log string into other stream ">duplicate()</a>: Duplicate log string into other stream  <a href="#a3c66d4096cbaac34db4659e04a0d6335">More...</a><br/></td></tr>
<tr class="separator:a3c66d4096cbaac34db4659e04a0d6335"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9753872b3edbc89389d22688fdc0afc2"><td class="memItemLeft" align="right" valign="top">static bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qlog_8c.html#a9753872b3edbc89389d22688fdc0afc2">flush_</a> (qlog_t *log)</td></tr>
<tr class="memdesc:a9753872b3edbc89389d22688fdc0afc2"><td class="mdescLeft">&#160;</td><td class="mdescRight">qlog-&gt;flush(): Flush buffered log  <a href="#a9753872b3edbc89389d22688fdc0afc2">More...</a><br/></td></tr>
<tr class="separator:a9753872b3edbc89389d22688fdc0afc2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a58ed43ff476576586b46c4f6744f1fd2"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qlog_8c.html#a58ed43ff476576586b46c4f6744f1fd2">free_</a> (qlog_t *log)</td></tr>
<tr class="memdesc:a58ed43ff476576586b46c4f6744f1fd2"><td class="mdescLeft">&#160;</td><td class="mdescRight">qlog-&gt;free(): Close ratating-log file &amp; de-allocate resources  <a href="#a58ed43ff476576586b46c4f6744f1fd2">More...</a><br/></td></tr>
<tr class="separator:a58ed43ff476576586b46c4f6744f1fd2"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Rotating file logger object. </p>
<p>qlog implements a auto-rotating file logger.</p>
<div class="fragment"><div class="line"><span class="comment">// create a daily-rotating log file.</span></div>
<div class="line">qlog_t *log = <a class="code" href="qlog_8c.html#acfc1a51cddb0a4e8555ea66f42276874">qlog</a>(<span class="stringliteral">&quot;/tmp/dailylog-%Y%m%d.err&quot;</span>, 0644, 86400, <span class="keyword">false</span>);</div>
<div class="line"><span class="keywordflow">if</span>(log == NULL) <span class="keywordflow">return</span>;</div>
<div class="line"></div>
<div class="line"><span class="comment">// screen out.</span></div>
<div class="line">log-&gt;duplicate(log, stdout, <span class="keyword">true</span>);</div>
<div class="line"></div>
<div class="line"><span class="comment">// write logs.</span></div>
<div class="line">log-&gt;write(log, <span class="stringliteral">&quot;Service started.&quot;</span>);</div>
<div class="line">log-&gt;writef(log, <span class="stringliteral">&quot;Server Id: %d&quot;</span>, 1);</div>
<div class="line"></div>
<div class="line"><span class="comment">// close and release resources.</span></div>
<div class="line">log-&gt;free(log);</div>
</div><!-- fragment --> 
<p>Definition in file <a class="el" href="qlog_8c_source.html">qlog.c</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="acfc1a51cddb0a4e8555ea66f42276874"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">qlog_t* qlog </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>filepathfmt</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">mode_t&#160;</td>
          <td class="paramname"><em>mode</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>rotateinterval</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>options</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Open ratating-log file. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filepathfmt</td><td>filename format. formatting argument is same as strftime() </td></tr>
    <tr><td class="paramname">mode</td><td>new file mode. 0 for system default </td></tr>
    <tr><td class="paramname">rotateinterval</td><td>rotating interval seconds, set 0 to disable rotation </td></tr>
    <tr><td class="paramname">options</td><td>combination of options.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer of qlog_t structure</dd></dl>
<dl class="section note"><dt>Note</dt><dd>rotateinterval is not relative time. If you set it to 3600, log file will be rotated at every hour. And filenameformat is same as strftime(). So If you want to log with hourly rotating, filenameformat must be defined including hour format like "/somepath/xxx-%Y%m%d%H.log". You can set it to "/somepath/xxx-%H.log" for daily overrided log file.</dd>
<dd>
Available options:<ul>
<li>QLOG_OPT_THREADSAFE - make it thread-safe.</li>
<li>QLOG_OPT_FLUSH - flush out buffer everytime.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">qlog_t *log = <a class="code" href="qlog_8c.html#acfc1a51cddb0a4e8555ea66f42276874">qlog</a>(<span class="stringliteral">&quot;/tmp/qdecoder-%Y%m%d.err&quot;</span>, 0644, 86400, QLOG_OPT_THREADSAFE);</div>
<div class="line">log-&gt;free(log);</div>
</div><!-- fragment --> 
<p>Definition at line <a class="el" href="qlog_8c_source.html#l00105">105</a> of file <a class="el" href="qlog_8c_source.html">qlog.c</a>.</p>

</div>
</div>
<a class="anchor" id="a1d9678a766dbbe0cf4863296588a70ce"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static bool write_ </td>
          <td>(</td>
          <td class="paramtype">qlog_t *&#160;</td>
          <td class="paramname"><em>log</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>str</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>qlog-&gt;write(): Log messages </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">log</td><td>a pointer of qlog_t </td></tr>
    <tr><td class="paramname">str</td><td>message string</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherewise returns false </dd></dl>

<p>Definition at line <a class="el" href="qlog_8c_source.html#l00160">160</a> of file <a class="el" href="qlog_8c_source.html">qlog.c</a>.</p>

</div>
</div>
<a class="anchor" id="a0f1c08e4e0616731b8c5be87a8752f72"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static bool writef </td>
          <td>(</td>
          <td class="paramtype">qlog_t *&#160;</td>
          <td class="paramname"><em>log</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>format</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>...</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>qlog-&gt;<a class="el" href="qlog_8c.html#a0f1c08e4e0616731b8c5be87a8752f72" title="qlog-&gt;writef(): Log messages ">writef()</a>: Log messages </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">log</td><td>a pointer of qlog_t </td></tr>
    <tr><td class="paramname">format</td><td>messages format</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherewise returns false </dd></dl>

<p>Definition at line <a class="el" href="qlog_8c_source.html#l00199">199</a> of file <a class="el" href="qlog_8c_source.html">qlog.c</a>.</p>

</div>
</div>
<a class="anchor" id="a3c66d4096cbaac34db4659e04a0d6335"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static bool duplicate </td>
          <td>(</td>
          <td class="paramtype">qlog_t *&#160;</td>
          <td class="paramname"><em>log</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">FILE *&#160;</td>
          <td class="paramname"><em>outfp</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>flush</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>qlog-&gt;<a class="el" href="qlog_8c.html#a3c66d4096cbaac34db4659e04a0d6335" title="qlog-&gt;duplicate(): Duplicate log string into other stream ">duplicate()</a>: Duplicate log string into other stream </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">log</td><td>a pointer of qlog_t </td></tr>
    <tr><td class="paramname">fp</td><td>logging messages will be printed out into this stream. set NULL to disable. </td></tr>
    <tr><td class="paramname">flush</td><td>set to true if you want to flush everytime duplicating.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherewise returns false</dd></dl>
<div class="fragment"><div class="line">log-&gt;duplicate(log, stdout, <span class="keyword">true</span>); <span class="comment">// enable console out with flushing</span></div>
<div class="line">log-&gt;duplicate(log, stderr, <span class="keyword">false</span>);    <span class="comment">// enable console out</span></div>
<div class="line">log-&gt;duplicate(log, NULL, <span class="keyword">false</span>);  <span class="comment">// disable console out (default)</span></div>
</div><!-- fragment --> 
<p>Definition at line <a class="el" href="qlog_8c_source.html#l00230">230</a> of file <a class="el" href="qlog_8c_source.html">qlog.c</a>.</p>

</div>
</div>
<a class="anchor" id="a9753872b3edbc89389d22688fdc0afc2"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static bool flush_ </td>
          <td>(</td>
          <td class="paramtype">qlog_t *&#160;</td>
          <td class="paramname"><em>log</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>qlog-&gt;flush(): Flush buffered log </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">log</td><td>a pointer of qlog_t</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherewise returns false </dd></dl>

<p>Definition at line <a class="el" href="qlog_8c_source.html#l00249">249</a> of file <a class="el" href="qlog_8c_source.html">qlog.c</a>.</p>

</div>
</div>
<a class="anchor" id="a58ed43ff476576586b46c4f6744f1fd2"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static void free_ </td>
          <td>(</td>
          <td class="paramtype">qlog_t *&#160;</td>
          <td class="paramname"><em>log</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>qlog-&gt;free(): Close ratating-log file &amp; de-allocate resources </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">log</td><td>a pointer of qlog_t </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="qlog_8c_source.html#l00269">269</a> of file <a class="el" href="qlog_8c_source.html">qlog.c</a>.</p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_40c73bf2095fd0473b1b85ccdcac2768.html">extensions</a></li><li class="navelem"><a class="el" href="qlog_8c.html">qlog.c</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 </li>
  </ul>
</div>
</body>
</html>
